from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse, Http404, HttpResponseForbidden
from django.template import loader
# Create your views here.
from movies.models import Test
from django.views.generic import ListView,DetailView

def test1(request):
    # return HttpResponse("Hello, world!")
    raise Http404('')


def test2(request):
    return render(request, 'movies/index.html')


def test3(request):
    from movies.models import Test
    user = Test.objects.all()[0]

    return render(request, 'movies/index2.html', context={'name': user.name})


def test4(request):
    user = Test.objects.all()[0]
    return render(request, 'movies/index2.html', context={'name': user.name})


def test5(request):
    from django.template import loader
    t = loader.get_template('movies/index.html')
    return HttpResponse(t.render({}, request))


def test6(request):
    return redirect('https://www.baidu.com')


def test7(request):
    obj = get_object_or_404(Test, pk=1)

    return HttpResponse(obj.name)


from django.views.decorators.http import require_http_methods


@require_http_methods(['GET'])
def test8(request):
    return HttpResponse('hello')


class test9(DetailView):

    pass



def test10(request):
    from movies.forms import LoginForm
    method = request.method

    if method == "GET":
        login_form = LoginForm()
        return render(request,'test1/login_test.html',{'form':login_form})
    elif method == "POST":
        account = request.POST['account']
        password = request.POST['password']
        return HttpResponse('POST')



